package com.sharingsperejdbc.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.sharingsperejdbc.demo.entity.SysLog;
import com.sharingsperejdbc.demo.service.BaseServiceImpl;
import org.apache.shardingsphere.core.strategy.keygen.SnowflakeShardingKeyGenerator;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wwz
 */
@Controller
@RequestMapping
public class BaseController {

    @Autowired
    private BaseServiceImpl baseService;

    @RequestMapping("/index")
    @ResponseBody
    public Object index(){
        //ShardingKeyGenerator
        SysLog sysLog = new SysLog();
        sysLog.setName("wwz");
//        SnowflakeShardingKeyGenerator snowflakeShardingKeyGenerator = new SnowflakeShardingKeyGenerator();
//        sysLog.setId(snowflakeShardingKeyGenerator.getWorkerId());
        baseService.insert(sysLog);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",baseService.selectList(Condition.create()));
        return jsonObject;
    }


    @RequestMapping("/selectDetail")
    @ResponseBody
    public Object selectDetail(Long id){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("detail",baseService.selectList(Condition.create().eq("id",id)));
        return jsonObject;
    }
}
